<template>
  <div class="week-plan-detail-container">
    <!-- 顶部公共信息区域 -->
    <div class="header-section">
      <h1 class="title"
        >广西幼师实验幼儿园{{ weekData.className || '' }}第{{ weekData.weekNumber }}周计划</h1
      >
      <div class="summary-card">
        <div class="public-info">
          <div class="flex gap-col-10px">
            <div class="info-item flex-1">
              <div class="info-title">周次：</div>
              <div class="info-content">第{{ weekData.weekNumber }}周</div>
            </div>
            <div class="info-item flex-1">
              <div class="info-title">时间：</div>
              <div class="info-content"
                >{{ formatDate(weekData.startDate, 'YYYY-MM-DD') }} 至
                {{ formatDate(weekData.endDate, 'YYYY-MM-DD') }}</div
              >
            </div>
          </div>
          <div class="flex gap-col-10px">
            <div class="info-item flex-1">
              <div class="info-title">教师：</div>
              <div class="info-content">{{ weekData.teacherName }}</div>
            </div>
            <div class="info-item flex-1">
              <div class="info-title">保育教师：</div>
              <div class="info-content">{{ weekData.nurseryTeacherName }}</div>
            </div>
          </div>
          <div class="info-item">
            <div class="info-title">周主题：</div>
            <div class="info-content">{{ weekData.topicName }}</div>
          </div>
        </div>

        <el-card class="info-card" v-if="weekData.workFocus">
          <div class="info-title">
            <el-icon :size="18" color="#409EFF"><Document /></el-icon>
            <span>工作重点</span>
          </div>
          <p class="info-text">{{ weekData.workFocus }}</p>
        </el-card>

        <el-card class="info-card" v-if="weekData.parentCoop">
          <div class="info-title">
            <el-icon :size="18" color="#67C23A"><User /></el-icon>
            <span>家长配合</span>
          </div>
          <p class="info-text">{{ weekData.parentCoop }}</p>
        </el-card>

        <el-card class="info-card" v-if="weekData.happyLife">
          <div class="info-title">
            <el-icon :size="18" color="#E6A23C"><Sunny /></el-icon>
            <span>快乐生活</span>
          </div>
          <p class="info-text">{{ weekData.happyLife }}</p>
        </el-card>
      </div>
    </div>

    <!-- 每日内容展示区域 -->
    <div class="daily-plan-section">
      <div class="section-header">
        <el-icon><Calendar /></el-icon>
        <h2>周计划每日内容</h2>
      </div>
      <el-tabs v-model="activeDay" class="weekly-tabs">
        <el-tab-pane
          v-for="day in weekData.dailyList"
          :key="day.dayOfWeek"
          :label="daysOfWeek['day' + day.dayOfWeek]"
          :name="'day' + day.dayOfWeek"
        >
          <div class="day-detail">
            <!-- <div class="day-info">
              <span class="day-title">{{ daysOfWeek['day' + day.dayOfWeek] }}</span>
              <span class="weekdate">({{}})</span>
            </div> -->

            <div class="activities-container">
              <div class="activity-type" v-for="(item, key) in dailyData" :key="key">
                <div class="type-header game">
                  <div class="section-label">{{ key }}</div></div
                >
                <div class="activity-items">
                  <!-- 运动 -->
                  <div class="activity-item" v-for="subItem in item" :key="subItem.id">
                    <div class="item-label">
                      <i class="el-icon-bicycle"></i> {{ subItem.label }}</div
                    >
                    <div class="item-content" id="sportContent">
                      {{ day[subItem.key] }}
                    </div>
                    <div class="item-actions">
                      <el-button
                        class="action-btn btn-view"
                        type="primary"
                        @click="handleClickView(day, subItem.value)"
                      >
                        <i class="el-icon-view"></i> 查看反馈记录
                      </el-button>
                      <el-button
                        class="action-btn btn-upload"
                        type="primary"
                        plain
                        @click="handleClickUpload(day, subItem.value)"
                      >
                        <ElIcon class="mr-2px"><Plus /></ElIcon> 新增反馈
                      </el-button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
      <ElEmpty v-if="!weekData?.dailyList?.length" />
    </div>
    <feedbackFormDialog ref="feedbackFormDialogRef" />
  </div>
</template>

<script lang="ts" setup>
import { Document, User, Sunny, Calendar, Plus } from '@element-plus/icons-vue'
import { formatDate } from '@/utils/formatTime'
import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
import feedbackFormDialog from './feedbackFormDialog.vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const props = defineProps({
  weekData: {
    type: Object,
    required: true
  }
})

// 响应式数据
const activeDay = ref('day2')
const feedbackFormDialogRef = ref()
// 日期定义
const daysOfWeek: any = reactive({
  day1: '周一',
  day2: '周二',
  day3: '周三',
  day4: '周四',
  day5: '周五',
  day6: '周六',
  day7: '周日'
})
watch(
  () => props.weekData.dailyList,
  (list) => {
    console.log(list, list?.length, '---v')
    if (list?.length) {
      const day = list[0]
      activeDay.value = 'day' + day.dayOfWeek
    }
    console.log(activeDay.value, list?.length, '---v')
  },
  {
    deep: true,
    immediate: true
  }
)
const handleClickView = (item, type?: any) => {
  router.push('/classes/feedbackRecord?dailyId=' + item.id + '&weeklyType=' + type)
}
const dailyData: any = ref({})
const setDailyData = () => {
  const keyMap = ['happyLearningTeach', 'happyLearningGame', 'happyGameSport', 'happyGameGame']
  const weeklyDatiyTypeList = getStrDictOptions(DICT_TYPE.SCHOOL_WEEKLY_DAILY_TYPE)
  weeklyDatiyTypeList.forEach((element, index) => {
    const lable = element.label
    const keyName = lable.split('-')[0]
    const childName = lable.split('-')[1]
    if (!dailyData.value[keyName]) {
      dailyData.value[keyName] = []
    }
    dailyData.value[keyName].push({
      label: childName,
      value: element.value,
      key: keyMap[index]
    })
  })
  console.log(weeklyDatiyTypeList, dailyData, '---weeklyDatiyTypeList')
}
setDailyData()
const handleClickUpload = (item, type?: any) => {
  feedbackFormDialogRef.value.open('create', {
    id: item.id,
    weeklyType: type
  })
}
</script>

<style lang="scss" scoped>
.week-plan-detail-container {
  width: 100%;
  max-width: 1200px;
  padding: 20px;
  margin: 0 auto;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  white-space: pre-wrap;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 5%);

  .header-section {
    margin-bottom: 30px;

    .title {
      padding-bottom: 15px;
      margin-bottom: 25px;
      font-size: 22px;
      font-weight: 600;
      color: #303133;
      text-align: center;
      border-bottom: 1px solid #ebeef5;
    }

    .summary-card {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 20px;

      .public-info {
        padding: 25px;
        background-color: #f5f7fa;
        border-radius: 6px;

        .info-item {
          display: flex;
          margin-bottom: 18px;

          &:last-child {
            margin-bottom: 0;
          }

          .info-label {
            width: 80px;
            font-weight: 600;
            color: #606266;
          }

          .info-content {
            font-size: 16px;
            color: #303133;
            flex: 1;
          }
        }
      }

      .info-card {
        border: 1px solid #ebeef5;
        border-radius: 6px;
        box-shadow: none;

        .info-title {
          display: flex;
          align-items: center;
          margin-bottom: 12px;
          font-weight: 500;
          color: var(--el-color-info);

          span {
            margin-left: 8px;
          }
        }

        .info-text {
          padding-left: 26px;
          margin: 0;
          line-height: 1.6;
          color: #303133;
        }
      }

      .info-title {
        font-weight: 500;
        color: var(--el-color-info);
      }
    }
  }

  .daily-plan-section {
    padding-top: 20px;
    border-top: 1px solid #ebeef5;

    .section-header {
      display: flex;
      align-items: center;
      margin-bottom: 20px;

      h2 {
        margin: 0 0 0 10px;
        font-size: 18px;
        color: #303133;
      }
    }

    .day-detail {
      padding: 20px;
      background-color: #f9fbfd;
      border: 1px solid #ebeef5;
      border-radius: 6px;

      .day-info {
        margin-bottom: 20px;

        .day-title {
          font-size: 18px;
          font-weight: 600;
          color: #409eff;
        }

        .weekdate {
          margin-left: 10px;
          font-size: 14px;
          color: #909399;
        }
      }

      .activities-container {
        .activity-table {
          overflow: hidden;
          border-radius: 6px;

          :deep(th) {
            font-weight: 600;
            background-color: #ecf5ff;
          }

          :deep() {
            tr {
              &:first-child {
                th {
                  background-color: #fff;
                }
              }
            }
          }
        }

        .activity-type {
          position: relative;
          margin-bottom: 25px;
          overflow: hidden;
          border-radius: 8px;
          box-shadow: 0 2px 10px rgb(0 0 0 / 5%);
        }

        .type-header {
          display: flex;
          padding: 12px 20px;
          font-size: 16px;
          font-weight: 600;
          color: white;
          background-color: #fff;
          align-items: center;
        }

        .type-header.game {
          // background: linear-gradient(to right, #e6a23c, #f0c570);
        }

        .type-header i {
          margin-right: 8px;
        }

        .activity-items {
          background: white;
        }

        .activity-item {
          display: flex;
          align-items: center;
          padding: 18px 20px;
          border-bottom: 1px solid #f1f5f9;
          transition: background-color 0.3s;
        }

        .activity-item:last-child {
          border-bottom: none;
        }

        .activity-item:hover {
          background-color: #f8fbff;
        }

        .item-label {
          display: flex;
          width: 100px;
          font-size: 15px;
          font-weight: 600;
          color: #4a5568;
          align-items: center;
          flex-shrink: 0;
        }

        .item-label i {
          margin-right: 8px;
          color: #409eff;
        }

        .item-content {
          min-height: 22px;
          padding: 0 15px;
          font-size: 14px;
          color: #5a6270;
          flex: 1;
        }

        .item-actions {
          flex-shrink: 0;
        }

        .empty-content {
          font-style: italic;
          color: #a3adb9;
        }

        .additional-activities {
          margin-top: 25px;

          .additional-title {
            padding-left: 10px;
            margin-bottom: 15px;
            font-size: 16px;
            color: #606266;
            border-left: 4px solid #409eff;
          }

          .activity-card {
            padding: 15px;
            margin-bottom: 15px;
            background-color: #fff;
            border-left: 3px solid #67c23a;
            border-radius: 6px;
            box-shadow: 0 1px 4px rgb(0 0 0 / 5%);

            .activity-header {
              display: flex;
              justify-content: space-between;
              margin-bottom: 10px;

              .activity-title {
                font-weight: 600;
                color: #303133;
              }
            }

            .activity-desc {
              line-height: 1.6;
              color: #606266;
            }
          }
        }
      }
    }
  }

  .section-label {
    position: relative;
    padding-left: 12px;
    font-size: 16px;
    font-weight: 600;
    color: #606266;
  }

  .section-label::before {
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 0;
    width: 4px;
    background-color: var(--el-color-primary);
    border-radius: 2px;
    content: '';
  }

  .footer-actions {
    display: flex;
    padding-top: 20px;
    margin-top: 40px;
    border-top: 1px solid #ebeef5;
    justify-content: center;
    gap: 20px;

    .el-button {
      padding: 12px 28px;
      font-weight: 500;
    }
  }
}
</style>
